<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      arr = [1, 2, 3, 4, 5]

      // push方法

      // Array.prototype.myPush = function (...agu) {
      //   for (let i = 0; i < agu.length; i++) {
      //     this[this.length]=agu[i]
      //   }
      //   return this
      // }
      // console.log(arr.myPush(2,2));

      // pop方法

      // Array.prototype.myPop = function () {
      //   if(this.length===0) return undefined
      //   this.length = this.length - 1
      //   return this
      // }
      // console.log(arr.myPop())

      // unshift方法

      // Array.prototype.myUnshift = function (...agu) {
      //   let newArr = [...agu, ...this]
      //   arr = newArr
      //   return this
      // }
      // console.log(arr.myUnshift(9))
      // console.log(arr)

      // shift方法

      // Array.prototype.myShift = function () {
      //   if (this.length === 0) return undefined
      //   for (let i = 0; i < this.length - 1; i++) {
      //     this[i] = this[i + 1]
      //   }
      //   this.length--
      //   return this
      // }
      // console.log(arr.myShift())

      // reverse方法
      // Array.prototype.myReverse = function () {
      //   if (this.length === 0) return undefined
      //   const item = this.length
      //   for (let i = 0, j = item - 1; i < j; i++, j--) {
      //     ;[this[i], this[j]] = [this[j], this[i]]
      //   }
      //   return this
      // }
      // console.log(arr.myReverse());
    </script>
  </body>
</html>
